<!DOCTYPE html>
<html lang="en">


<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>登录系统</title>
  <link rel="stylesheet" href="/plugins/fontawesome-free/css/all.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/dist/css/adminlte.min.css">
  <link rel="stylesheet" href="/plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <link rel="stylesheet" href="/my_works/css/readme.css">
  <link rel="stylesheet" href="/plugins/toastr/toastr.min.css">
  <link rel="stylesheet" href="/plugins/sweetalert2/sweetalert2.min.css">
  <script src="/plugins/toastr/toastr.min.js"></script>
  <script src="/plugins/sweetalert2/sweetalert2.min.js"></script>
</head>

<body class="login-page" style="min-height: 466px;">
  <div class="login-box">
    <!-- /.login-logo -->
    <div class="card card-outline card-primary">
      <div class="card-header text-center">
        <a class="h1">简易成绩管理系统</a>
      </div>
      <div class="card-body">
        <p class="login-box-msg">登录以开始</p>

        <form action="#" method="post">
          <div class="input-group mb-3">
            <input type="text" class="form-control" placeholder="工号" id="no">
            <div class="input-group-append">
              <div class="input-group-text">
                <span class="fas fa-envelope"></span>
              </div>
            </div>
          </div>
          <div class="input-group mb-3">
            <input type="password" class="form-control" placeholder="密码" id="password">
            <div class="input-group-append">
              <div class="input-group-text">
                <span class="fas fa-lock"></span>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="col-8">
              <div class="icheck-primary">
                <label for="remember">
                  选择登录身份
                </label>
                <div class="form-check">
                  <input class="form-check-input" type="radio" name="exampleRadios" id="studentRadio" value="student"
                    checked>
                  <label class="form-check-label" for="studentRadio">
                    学生
                  </label>
                </div>
                <div class="form-check">
                  <input class="form-check-input" type="radio" name="exampleRadios" id="teacherRadio" value="teacher">
                  <label class="form-check-label" for="teacherRadio">
                    教师
                  </label>
                </div>
                <div class="form-check">
                  <input class="form-check-input" type="radio" name="exampleRadios" id="managerRadio" value="manager">
                  <label class="form-check-label" for="managerRadio">
                    管理员
                  </label>
                </div>
              </div>
            </div>
            <!-- /.col -->
            <div class="col-4">
              <button type="button" class="btn btn-primary btn-block btn-lg" onclick="login()">登录</button>
            </div>
            <!-- /.col -->
          </div>
        </form>


        <a class="text-center">忘记密码请咨询管理员</a>
        </p>
      </div>
      <!-- /.card-body -->
    </div>
    <!-- /.card -->
  </div>
  <!-- /.login-box -->

  <!-- jQuery -->
  <script src="/plugins/jquery/jquery.min.js"></script>
  <!-- Bootstrap 4 -->
  <script src="/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
  <!-- AdminLTE App -->
  <script src="/dist/js/adminlte.min.js"></script>
  <script src="/plugins/axios/axios.min.js"></script>
  <script src="/my_works/common/common.js"></script>
  <script>
    //登录用函数
    login = () => {
      //进行表单验证
      no = $("#no").val()
      password = $("#password").val()
      if (no.length < 5) {
        errorInfo("工号不能为空并且不能低于5位");
        return;
      }
      if (password.length <= 5) {
        errorInfo("密码不能为空并且不能低于5位");
        return;
      }
      if ($("#studentRadio:checked").val()) {
        //学生方式登陆
        // console.log("学生");
        axios({
          url: "/api/student/login",
          method: "post",
          data: {
            no: no,
            password: password
          }
        }).then((res) => {
          successInfo("登录成功,正在跳转");
          localStorage.setItem("no", no);
          localStorage.setItem("id", res.data.data.id);
          localStorage.setItem("name", res.data.data.name);
          setTimeout(() => {
            window.location = "/my_works/index_student.html"
          }, 1000);
        })
      } else if ($("#teacherRadio:checked").val()) {
        //教师方式登录
        // console.log("教师");
        axios({
          url: "/api/teacher/login",
          method: "post",
          data: {
            no: no,
            password: password
          }
        }).then((res) => {
          successInfo("登录成功,正在跳转");
          localStorage.setItem("no", no);
          localStorage.setItem("id", res.data.data.id);
          localStorage.setItem("name", res.data.data.name);
          setTimeout(() => {
            window.location = "/my_works/index_teacher.html"
          }, 1000);
        })
      } else {
        //管理员方式登录
        axios({
          url: "/api/teacher/login/admin",
          method: "post",
          data: {
            no: no,
            password: password
          }
        }).then((res) => {
          successInfo("登录成功,正在跳转");
          localStorage.setItem("no", no);
          localStorage.setItem("id", res.data.data.id);
          localStorage.setItem("name", res.data.data.name);
          setTimeout(() => {
            window.location = "/my_works/index_admin.html"
          }, 1000);
        })

      }
    }
  </script>


</body>

</html>